/**
 * @brief Serial driver implementation
 * @author Gilad Avidov
 */
#include <mcs51reg.h>
#include "serial.h"
#include "sched.h"

void putchar(char c)
{
	while (!TI);// compare asm code generated for these three lines
	TI = 0;  	// clear TI flag
	SBUF = c;  	// load serial port with transmit value

}

char getchar_no_sched ()
{
    while (!RI) ;    // compare asm code generated for these three lines
	RI = 0;			// clear RI flag
	return SBUF;  	// return character from SBUF
}

char getchar ()
{
    while (!RI) sched_sleep_ticks(1);    // compare asm code generated for these three lines
	RI = 0;			// clear RI flag
	return SBUF;  	// return character from SBUF
}

void serial_init()
{
    TMOD = 0x20;
    SCON = 0x52;
    TH1  = 0xFD;
    TR1  = 0x1;
    TL1  = 0x0;
}

